﻿using System;
using System.Collections;
using System.Data;
using CE.Database;
using CE.Security;

/// <summary>
/// Summary description for ReferenceUserOtherDetailsDB
/// </summary>
/// 
namespace CE.User
{
    public class ReferenceUserOtherDetailsDB
    {
        public ReferenceUserOtherDetailsDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ReferenceUserOtherDetails referenceuserotherdetails)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocReferenceUserOtherDetailInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@UserId", referenceuserotherdetails.UserId);
            _sPara.Add("@CECarId", referenceuserotherdetails.CeCarId);
            _sPara.Add("@IsParallelImport", referenceuserotherdetails.IsParallelImport);
            _sPara.Add("@IsCNGVehicle", referenceuserotherdetails.IsCNGVehicle);
            _sPara.Add("@IsHybridModel", referenceuserotherdetails.IsHybridModel);
            _sPara.Add("@DrivingLicensePassDate", referenceuserotherdetails.DrivingLicensePassDate);
            _sPara.Add("@NOCLast3", referenceuserotherdetails.NOCLast3);
            _sPara.Add("@NOCLast3Claim1NotAtFault", referenceuserotherdetails.NOCLast3Claim1NotAtFault);
            _sPara.Add("@NOCLast3Claim1AtFault", referenceuserotherdetails.NOCLast3Claim1AtFault);
            _sPara.Add("@NOCLast3Claim1Windscreen", referenceuserotherdetails.NOCLast3Claim1Windscreen);
            _sPara.Add("@NOCLast3Claim1AccidentDate", referenceuserotherdetails.NOCLast3Claim1AccidentDate);

            _sPara.Add("@NOCLast3Claim2NotAtFault", referenceuserotherdetails.NOCLast3Claim2NotAtFault);
            _sPara.Add("@NOCLast3Claim2AtFault", referenceuserotherdetails.NOCLast3Claim2AtFault);
            _sPara.Add("@NOCLast3Claim2Windscreen", referenceuserotherdetails.NOCLast3Claim2Windscreen);
            _sPara.Add("@NOCLast3Claim2AccidentDate", referenceuserotherdetails.NOCLast3Claim2AccidentDate);

            _sPara.Add("@NOCLast3Claim3NotAtFault", referenceuserotherdetails.NOCLast3Claim3NotAtFault);
            _sPara.Add("@NOCLast3Claim3AtFault", referenceuserotherdetails.NOCLast3Claim3AtFault);
            _sPara.Add("@NOCLast3Claim3Windscreen", referenceuserotherdetails.NOCLast3Claim3Windscreen);
            _sPara.Add("@NOCLast3Claim3AccidentDate", referenceuserotherdetails.NOCLast3Claim3AccidentDate);

            _sPara.Add("@NOCLast2", referenceuserotherdetails.NOCLast2);
            _sPara.Add("@NOCLast2Claim1NotAtFault", referenceuserotherdetails.NOCLast2Claim1NotAtFault);
            _sPara.Add("@NOCLast2Claim1AtFault", referenceuserotherdetails.NOCLast2Claim1AtFault);
            _sPara.Add("@NOCLast2Claim1Windscreen", referenceuserotherdetails.NOCLast2Claim1Windscreen);
            _sPara.Add("@NOCLast2Claim1AccidentDate", referenceuserotherdetails.NOCLast2Claim1AccidentDate);

            _sPara.Add("@NOCLast2Claim2NotAtFault", referenceuserotherdetails.NOCLast2Claim2NotAtFault);
            _sPara.Add("@NOCLast2Claim2AtFault", referenceuserotherdetails.NOCLast2Claim2AtFault);
            _sPara.Add("@NOCLast2Claim2Windscreen", referenceuserotherdetails.NOCLast2Claim2Windscreen);
            _sPara.Add("@NOCLast2Claim2AccidentDate", referenceuserotherdetails.NOCLast2Claim2AccidentDate);

            _sPara.Add("@NOCLast2Claim3NotAtFault", referenceuserotherdetails.NOCLast2Claim3NotAtFault);
            _sPara.Add("@NOCLast2Claim3AtFault", referenceuserotherdetails.NOCLast2Claim3AtFault);
            _sPara.Add("@NOCLast2Claim3Windscreen", referenceuserotherdetails.NOCLast2Claim3Windscreen);
            _sPara.Add("@NOCLast2Claim3AccidentDate", referenceuserotherdetails.NOCLast2Claim3AccidentDate);

            _sPara.Add("@NOCLast1", referenceuserotherdetails.NOCLast1);
            _sPara.Add("@NOCLast1Claim1NotAtFault", referenceuserotherdetails.NOCLast1Claim1NotAtFault);
            _sPara.Add("@NOCLast1Claim1AtFault", referenceuserotherdetails.NOCLast1Claim1AtFault);
            _sPara.Add("@NOCLast1Claim1Windscreen", referenceuserotherdetails.NOCLast1Claim1Windscreen);
            _sPara.Add("@NOCLast1Claim1AccidentDate", referenceuserotherdetails.NOCLast1Claim1AccidentDate);

            _sPara.Add("@NOCLast1Claim2NotAtFault", referenceuserotherdetails.NOCLast1Claim2NotAtFault);
            _sPara.Add("@NOCLast1Claim2AtFault", referenceuserotherdetails.NOCLast1Claim2AtFault);
            _sPara.Add("@NOCLast1Claim2Windscreen", referenceuserotherdetails.NOCLast1Claim2Windscreen);
            _sPara.Add("@NOCLast1Claim2AccidentDate", referenceuserotherdetails.NOCLast1Claim2AccidentDate);

            _sPara.Add("@NOCLast1Claim3NotAtFault", referenceuserotherdetails.NOCLast1Claim3NotAtFault);
            _sPara.Add("@NOCLast1Claim3AtFault", referenceuserotherdetails.NOCLast1Claim3AtFault);
            _sPara.Add("@NOCLast1Claim3Windscreen", referenceuserotherdetails.NOCLast1Claim3Windscreen);
            _sPara.Add("@NOCLast1Claim3AccidentDate", referenceuserotherdetails.NOCLast1Claim3AccidentDate);

            _sPara.Add("@SuspensionOfLicense", referenceuserotherdetails.SuspensionOfLicense);
            _sPara.Add("@PolicyCancelled", referenceuserotherdetails.PolicyCancelled);
            _sPara.Add("@RenewalQuoteReceived", referenceuserotherdetails.RenewalQuoteReceived);
            _sPara.Add("@AddDriver", referenceuserotherdetails.AddDriver);

            _sPara.Add("@Driver1Relation", referenceuserotherdetails.Driver1Relation);
            _sPara.Add("@Driver1Name", referenceuserotherdetails.Driver1Name);
            _sPara.Add("@Driver1NRIC", referenceuserotherdetails.Driver1NRIC);
            _sPara.Add("@Driver1LicensePassDate", referenceuserotherdetails.Driver1LicensePassDate);

            _sPara.Add("@Driver2Relation", referenceuserotherdetails.Driver2Relation);
            _sPara.Add("@Driver2Name", referenceuserotherdetails.Driver2Name);
            _sPara.Add("@Driver2NRIC", referenceuserotherdetails.Driver2NRIC);
            _sPara.Add("@Driver2LicensePassDate", referenceuserotherdetails.Driver2LicensePassDate);

            _sPara.Add("@Driver3Relation", referenceuserotherdetails.Driver3Relation);
            _sPara.Add("@Driver3Name", referenceuserotherdetails.Driver3Name);
            _sPara.Add("@Driver3NRIC", referenceuserotherdetails.Driver3NRIC);
            _sPara.Add("@Driver3LicensePassDate", referenceuserotherdetails.Driver3LicensePassDate);

            _sPara.Add("@Driver4Relation", referenceuserotherdetails.Driver4Relation);
            _sPara.Add("@Driver4Name", referenceuserotherdetails.Driver4Name);
            _sPara.Add("@Driver4NRIC", referenceuserotherdetails.Driver4NRIC);
            _sPara.Add("@Driver4LicensePassDate", referenceuserotherdetails.Driver4LicensePassDate);

            _sPara.Add("@Driver5Relation", referenceuserotherdetails.Driver5Relation);
            _sPara.Add("@Driver5Name", referenceuserotherdetails.Driver5Name);
            _sPara.Add("@Driver5NRIC", referenceuserotherdetails.Driver5NRIC);
            _sPara.Add("@Driver5LicensePassDate", referenceuserotherdetails.Driver5LicensePassDate);

            _sPara.Add("@ViewedDetailId", referenceuserotherdetails.ViewedDetailId);
            _sPara.Add("@Status", referenceuserotherdetails.Status);
            _sPara.Add("@RefCEUserId", referenceuserotherdetails.RefCEUserId);

            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public ReferenceUserOtherDetails GetReferenceUserOtherDetails(Int64 RefCEUserId, Int64 CarId, Int64 UserId)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "sprocReferenceUserOtherDetailSelectSingleItem";
            ReferenceUserOtherDetails _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@RefCEUserId", RefCEUserId);
            _sPara.Add("@CeCarId", CarId);
            _sPara.Add("@UserId", UserId);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new ReferenceUserOtherDetails();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }

        private ReferenceUserOtherDetails FillDataRecord(DataTable myDataTable)
        {
            ReferenceUserOtherDetails myReferenceUser = new ReferenceUserOtherDetails();
            myReferenceUser.UserId = Convert.ToInt64(myDataTable.Rows[0]["UserId"].ToString());
            myReferenceUser.CeCarId = Convert.ToInt64(myDataTable.Rows[0]["CeCarId"].ToString());
            myReferenceUser.IsParallelImport = Convert.ToBoolean(myDataTable.Rows[0]["IsParallelImport"].ToString());
            myReferenceUser.IsCNGVehicle = Convert.ToBoolean(myDataTable.Rows[0]["IsCNGVehicle"].ToString());
            myReferenceUser.IsHybridModel = Convert.ToBoolean(myDataTable.Rows[0]["IsHybridModel"].ToString());
            myReferenceUser.DrivingLicensePassDate = Convert.ToDateTime(myDataTable.Rows[0]["DrivingLicensePassDate"].ToString());

            myReferenceUser.NOCLast3 = Convert.ToInt32(myDataTable.Rows[0]["NOCLast3"].ToString());
            myReferenceUser.NOCLast3Claim1NotAtFault = myDataTable.Rows[0]["NOCLast3Claim1NotAtFault"].ToString();
            myReferenceUser.NOCLast3Claim1AtFault = myDataTable.Rows[0]["NOCLast3Claim1AtFault"].ToString();
            myReferenceUser.NOCLast3Claim1Windscreen = myDataTable.Rows[0]["NOCLast3Claim1Windscreen"].ToString();
            myReferenceUser.NOCLast3Claim1AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast3Claim1AccidentDate"].ToString());

            myReferenceUser.NOCLast3Claim2NotAtFault = myDataTable.Rows[0]["NOCLast3Claim2NotAtFault"].ToString();
            myReferenceUser.NOCLast3Claim2AtFault = myDataTable.Rows[0]["NOCLast3Claim2AtFault"].ToString();
            myReferenceUser.NOCLast3Claim2Windscreen = myDataTable.Rows[0]["NOCLast3Claim2Windscreen"].ToString();
            myReferenceUser.NOCLast3Claim2AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast3Claim2AccidentDate"].ToString());

            myReferenceUser.NOCLast3Claim3NotAtFault = myDataTable.Rows[0]["NOCLast3Claim3NotAtFault"].ToString();
            myReferenceUser.NOCLast3Claim3AtFault = myDataTable.Rows[0]["NOCLast3Claim3AtFault"].ToString();
            myReferenceUser.NOCLast3Claim3Windscreen = myDataTable.Rows[0]["NOCLast3Claim3Windscreen"].ToString();
            myReferenceUser.NOCLast3Claim3AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast3Claim3AccidentDate"].ToString());

            myReferenceUser.NOCLast2 = Convert.ToInt32(myDataTable.Rows[0]["NOCLast2"].ToString());
            myReferenceUser.NOCLast2Claim1NotAtFault = myDataTable.Rows[0]["NOCLast2Claim1NotAtFault"].ToString();
            myReferenceUser.NOCLast2Claim1AtFault = myDataTable.Rows[0]["NOCLast2Claim1AtFault"].ToString();
            myReferenceUser.NOCLast2Claim1Windscreen = myDataTable.Rows[0]["NOCLast2Claim1Windscreen"].ToString();
            myReferenceUser.NOCLast2Claim1AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast2Claim1AccidentDate"].ToString());

            myReferenceUser.NOCLast2Claim2NotAtFault = myDataTable.Rows[0]["NOCLast2Claim2NotAtFault"].ToString();
            myReferenceUser.NOCLast2Claim2AtFault = myDataTable.Rows[0]["NOCLast2Claim2AtFault"].ToString();
            myReferenceUser.NOCLast2Claim2Windscreen = myDataTable.Rows[0]["NOCLast2Claim2Windscreen"].ToString();
            myReferenceUser.NOCLast2Claim2AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast2Claim2AccidentDate"].ToString());

            myReferenceUser.NOCLast2Claim3NotAtFault = myDataTable.Rows[0]["NOCLast2Claim3NotAtFault"].ToString();
            myReferenceUser.NOCLast2Claim3AtFault = myDataTable.Rows[0]["NOCLast2Claim3AtFault"].ToString();
            myReferenceUser.NOCLast2Claim3Windscreen = myDataTable.Rows[0]["NOCLast2Claim3Windscreen"].ToString();
            myReferenceUser.NOCLast2Claim3AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast2Claim3AccidentDate"].ToString());

            myReferenceUser.NOCLast1 = Convert.ToInt32(myDataTable.Rows[0]["NOCLast1"].ToString());
            myReferenceUser.NOCLast1Claim1NotAtFault = myDataTable.Rows[0]["NOCLast1Claim1NotAtFault"].ToString();
            myReferenceUser.NOCLast1Claim1AtFault = myDataTable.Rows[0]["NOCLast1Claim1AtFault"].ToString();
            myReferenceUser.NOCLast1Claim1Windscreen = myDataTable.Rows[0]["NOCLast1Claim1Windscreen"].ToString();
            myReferenceUser.NOCLast1Claim1AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast1Claim1AccidentDate"].ToString());

            myReferenceUser.NOCLast1Claim2NotAtFault = myDataTable.Rows[0]["NOCLast1Claim2NotAtFault"].ToString();
            myReferenceUser.NOCLast1Claim2AtFault = myDataTable.Rows[0]["NOCLast1Claim2AtFault"].ToString();
            myReferenceUser.NOCLast1Claim2Windscreen = myDataTable.Rows[0]["NOCLast1Claim2Windscreen"].ToString();
            myReferenceUser.NOCLast1Claim2AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast1Claim2AccidentDate"].ToString());

            myReferenceUser.NOCLast1Claim3NotAtFault = myDataTable.Rows[0]["NOCLast1Claim3NotAtFault"].ToString();
            myReferenceUser.NOCLast1Claim3AtFault = myDataTable.Rows[0]["NOCLast1Claim3AtFault"].ToString();
            myReferenceUser.NOCLast1Claim3Windscreen = myDataTable.Rows[0]["NOCLast1Claim3Windscreen"].ToString();
            myReferenceUser.NOCLast1Claim3AccidentDate = Convert.ToDateTime(myDataTable.Rows[0]["NOCLast1Claim3AccidentDate"].ToString());

            myReferenceUser.SuspensionOfLicense = Convert.ToBoolean(myDataTable.Rows[0]["SuspensionOfLicense"].ToString());
            myReferenceUser.PolicyCancelled = Convert.ToBoolean(myDataTable.Rows[0]["PolicyCancelled"].ToString());
            myReferenceUser.RenewalQuoteReceived = Convert.ToSingle(myDataTable.Rows[0]["RenewalQuoteReceived"].ToString());
            myReferenceUser.AddDriver = Convert.ToBoolean(myDataTable.Rows[0]["AddDriver"].ToString());

            myReferenceUser.Driver1Relation = myDataTable.Rows[0]["Driver1Relation"].ToString();
            myReferenceUser.Driver1Name = myDataTable.Rows[0]["Driver1Name"].ToString();
            myReferenceUser.Driver1NRIC = myDataTable.Rows[0]["Driver1NRIC"].ToString();
            myReferenceUser.Driver1LicensePassDate = Convert.ToDateTime(myDataTable.Rows[0]["Driver1LicensePassDate"].ToString());

            myReferenceUser.Driver2Relation = myDataTable.Rows[0]["Driver2Relation"].ToString();
            myReferenceUser.Driver2Name = myDataTable.Rows[0]["Driver2Name"].ToString();
            myReferenceUser.Driver2NRIC = myDataTable.Rows[0]["Driver2NRIC"].ToString();
            myReferenceUser.Driver2LicensePassDate = Convert.ToDateTime(myDataTable.Rows[0]["Driver2LicensePassDate"].ToString());

            myReferenceUser.Driver3Relation = myDataTable.Rows[0]["Driver3Relation"].ToString();
            myReferenceUser.Driver3Name = myDataTable.Rows[0]["Driver3Name"].ToString();
            myReferenceUser.Driver3NRIC = myDataTable.Rows[0]["Driver3NRIC"].ToString();
            myReferenceUser.Driver3LicensePassDate = Convert.ToDateTime(myDataTable.Rows[0]["Driver3LicensePassDate"].ToString());

            myReferenceUser.Driver4Relation = myDataTable.Rows[0]["Driver4Relation"].ToString();
            myReferenceUser.Driver4Name = myDataTable.Rows[0]["Driver4Name"].ToString();
            myReferenceUser.Driver4NRIC = myDataTable.Rows[0]["Driver4NRIC"].ToString();
            myReferenceUser.Driver4LicensePassDate = Convert.ToDateTime(myDataTable.Rows[0]["Driver4LicensePassDate"].ToString());

            myReferenceUser.Driver5Relation = myDataTable.Rows[0]["Driver5Relation"].ToString();
            myReferenceUser.Driver5Name = myDataTable.Rows[0]["Driver5Name"].ToString();
            myReferenceUser.Driver5NRIC = myDataTable.Rows[0]["Driver5NRIC"].ToString();
            myReferenceUser.Driver5LicensePassDate = Convert.ToDateTime(myDataTable.Rows[0]["Driver5LicensePassDate"].ToString());

            myReferenceUser.ViewedDetailId = Convert.ToInt64(myDataTable.Rows[0]["ViewedDetailId"].ToString());
            myReferenceUser.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());

            return myReferenceUser;

        }


    }
}